package com.qf.service.impl;

import com.qf.exception.CustomerException;
import com.qf.mapper.UserMapper;
import com.qf.pojo.User;
import com.qf.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * @author zdl
 * @date 2025/2/21
 */
@Service
public class UserServiceImpl implements UserService {
    @Resource
    private UserMapper userMapper;
    @Override
    public User loginByUser(User user, HttpSession session) {
        User user1 = userMapper.selectUserByUsername(user);
        if (user1 == null){
            throw  new CustomerException("40001","用户名不存在");
        }
        if (!(user.getPassword().equals(user1.getPassword()))){
            throw  new CustomerException("40002","密码错误");
        }
        session.setAttribute("login",user1);
        return user1;
    }
}
